package cate.game.play.skill.passive.talent;

import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 受击时，有50%概率反弹受到伤害的45%,不超过自身生命最大值的30%
 */
public class 反伤PH extends PassiveHandler {

	private int 概率;

	private double 系数;

	private double 生命系数;

	//概率=5000&系数=4500&生命系数=3000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
		系数 = args.getWDouble("系数", 0d);
		生命系数 = args.getWDouble("生命系数", 0d);
	}

	@Override
	public void afterSufferOneAttack(SkillActionCtx action, long totalDamage, boolean strike) {
		if (!XT.chance(概率)) {
			return;
		}
		double rebound = Math.min(totalDamage* 系数, skill.owner.attr.total().hpTotal() * 生命系数);
		action.getActor().attr.passiveHurt(action, skill.owner, rebound);
	}
}
